package com.itheima.service.Impl;

import com.itheima.mapper.LoginMapper;
import com.itheima.pojo.Emp;
import com.itheima.service.LoginService;
import com.itheima.utils.JwtUtils;
import com.itheima.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

@Service
public class LoginServiceImpl implements LoginService {
    @Autowired
    private LoginMapper loginMapper;
    @Override
    public Result loginusername(String username, String password) {
        //编写登录流程
        //查询数据库中是否有这个人的用户名与密码
        List<Emp>empList = loginMapper.select(username,password);
        if (empList.size()==0){
            return Result.error("错误的密码用户信息");
        }
        HashMap<String, Object> mapJWT = new HashMap<>();
        mapJWT.put("jwt",username);
        String jwt = JwtUtils.generateJwt(mapJWT);
        return Result.success(jwt);
    }
}
